import turtle
import math

def draw_square(pen, x, y, length):
    pen.penup()
    pen.goto(x - length / 2, y - length / 2)
    pen.setheading(0)
    pen.pendown()
    for _ in range(4):
        pen.forward(length)
        pen.left(90)

def draw_board(pen, step_len, j):
    pen.reset()
    pen.color('black')
    pen.pensize(1)

    center_x = j * (4 * step_len)
    center_y = 0

    # 绘制开始的三个方块
    for i in range(3):
        length_i = step_len * (i + 1)
        draw_square(pen, center_x, center_y, length_i)

    # 连接正方形的四边
    directions = [180, 0, 270, 90]
    for direction in directions:
        pen.penup()
        pen.goto(center_x, center_y)
        pen.setheading(direction)
        pen.pendown()
        pen.forward(step_len)

    # 绘制红色的方块
    pen.color('red')
    pen.pensize(3)
    draw_square(pen, center_x, center_y, 2 * step_len)

    # 绘制四条线段
    pen.color('black')
    pen.pensize(2)
    diag_len = step_len * 2 * math.sqrt(2)
    dist_to_center = step_len * math.sqrt(2)
    start_points = [(-1, 1), (1, 1), (1, -1), (-1, -1)]
    for start_point in start_points:
        start_x = center_x + start_point[0] * dist_to_center
        start_y = center_y + start_point[1] * dist_to_center
        pen.penup()
        pen.goto(start_x, start_y)
        pen.setheading(45 * start_points.index(start_point))
        pen.pendown()
        pen.forward(diag_len)

    pen.hideturtle()


canvas = turtle.Screen()
pen = turtle.Turtle()

step_len = 50
for j in range(2):
    draw_board(pen, step_len, j)

canvas.exitonclick()
